﻿<sdk:Page x:Class="SampleBrowser.Views.SampleAnnotations" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
           xmlns:doc="http://schemas.firstfloorsoftware.com/documenttoolkit"
           xmlns:dte="http://schemas.firstfloorsoftware.com/documenttoolkit/extensions"
           xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
           xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="Custom Annotations">
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="136" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid.Resources>
            <!-- settings and store shared by all InkEditor instances -->
            <dte:InkEditorSettings x:Key="InkEditorSettings" />
            <doc:AnnotationStore x:Key="AnnotationStore" />
            
            <doc:TextSelection x:Key="Selection" IsEnabled="True" />

            <ControlTemplate x:Key="InkDocumentViewerTemplate" TargetType="doc:DocumentViewer">
                <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                    <ScrollViewer x:Name="ScrollViewer" Background="Transparent" BorderThickness="0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                        <ItemsControl x:Name="Pages">
                            <i:Interaction.Behaviors>
                                <doc:PageVirtualizer />
                            </i:Interaction.Behaviors>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid Width="{Binding DesiredPageContainerSize.Width}"
                                          Height="{Binding DesiredPageContainerSize.Height}">
                                        <Border Background="White" BorderBrush="{StaticResource SliderTrackBrush}" BorderThickness="1" Margin="4" HorizontalAlignment="Center" VerticalAlignment="Center">
                                            <doc:FixedPageViewer FixedPage="{Binding FixedPage}" 
                                                                     FixedPageSize="{Binding FixedPageSize}"
                                                                     FixedPageError="{Binding FixedPageError}"
                                                                     Scale="{Binding DesiredPageScale}">
                                                <i:Interaction.Behaviors>
                                                    <doc:FixedPageAdorner Annotations="{Binding TextContainer.Annotations}" Selection="{Binding TextContainer.Selection}" />
                                                    <doc:NavigationBehavior TextContainer="{Binding TextContainer}" />
                                                    
                                                    <!-- attach ink editor to each fixed page viewer instance-->
                                                    <dte:InkEditor Settings="{StaticResource InkEditorSettings}" Store="{StaticResource AnnotationStore}" />
                                                </i:Interaction.Behaviors>
                                            </doc:FixedPageViewer>
                                        </Border>
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ScrollViewer>
                </Border>
            </ControlTemplate>

        </Grid.Resources>

        <TextBlock x:Name="HeaderText" Grid.ColumnSpan="2" Style="{StaticResource HeaderTextStyle}" Text="Custom Annotations"/>
        <TextBlock Grid.Row="1" Grid.ColumnSpan="2" Text="Select some text and right mouse click to display the annotation menu" Margin="0,0,0,4" />

        <doc:DocumentDataSource x:Name="DataSource" LoadError="DataSource_LoadError" />
        
        <!-- printer that includes annotation in output -->
        <doc:DocumentPrinter x:Name="Printer" DocumentDataSource="{Binding ElementName=DataSource}" Annotations="{StaticResource AnnotationStore}" PrintError="Printer_PrintError" />

        <doc:ThumbnailListBox x:Name="Thumbnails" Grid.Row="2" DocumentDataSource="{Binding ElementName=DataSource}" PageIndex="{Binding PageIndex, Mode=TwoWay, ElementName=Navigator}" />

        <doc:DocumentViewer x:Name="Viewer"
                            Grid.Column="1" Grid.Row="2"
                            Template="{StaticResource InkDocumentViewerTemplate}"
                            DocumentDataSource="{Binding ElementName=DataSource}"
                            Selection="{StaticResource Selection}"
                            ViewMode="{Binding SelectedViewMode, ElementName=ViewModePicker}">
            <toolkit:ContextMenuService.ContextMenu>
                <toolkit:ContextMenu x:Name="ContextMenu">
                    <toolkit:MenuItem Header="Enable ink editing">
                        <toolkit:MenuItem.Icon>
                            <Image Source="/SampleBrowser;component/Assets/Icons/ink.png" />
                        </toolkit:MenuItem.Icon>
                        <toolkit:MenuItem.Command>
                            <dte:EnableInkCommand InkEditorSettings="{StaticResource InkEditorSettings}" />
                        </toolkit:MenuItem.Command>
                    </toolkit:MenuItem>
                    <toolkit:MenuItem Header="Disable ink editing">
                        <toolkit:MenuItem.Command>
                            <dte:DisableInkCommand InkEditorSettings="{StaticResource InkEditorSettings}" />
                        </toolkit:MenuItem.Command>
                    </toolkit:MenuItem>
                    <toolkit:Separator />
                    <toolkit:MenuItem Header="Draw red ink" CommandParameter="Red">
                        <toolkit:MenuItem.Command>
                            <dte:InkCommand InkEditorSettings="{StaticResource InkEditorSettings}" />
                        </toolkit:MenuItem.Command>
                    </toolkit:MenuItem>
                    <toolkit:MenuItem Header="Draw green ink" CommandParameter="Green">
                        <toolkit:MenuItem.Command>
                            <dte:InkCommand InkEditorSettings="{StaticResource InkEditorSettings}" />
                        </toolkit:MenuItem.Command>
                    </toolkit:MenuItem>
                    <toolkit:MenuItem Header="Draw blue ink" CommandParameter="Blue">
                        <toolkit:MenuItem.Command>
                            <dte:InkCommand InkEditorSettings="{StaticResource InkEditorSettings}" />
                        </toolkit:MenuItem.Command>
                    </toolkit:MenuItem>
                    <toolkit:MenuItem Header="Remove ink" CommandParameter="">
                        <toolkit:MenuItem.Command>
                            <dte:InkCommand InkEditorSettings="{StaticResource InkEditorSettings}" />
                        </toolkit:MenuItem.Command>
                    </toolkit:MenuItem>
                    <toolkit:Separator />
                    <toolkit:MenuItem Header="Add sticky note" CommandParameter="{Binding HorizontalOffset, ElementName=ContextMenu}">
                        <toolkit:MenuItem.Icon>
                            <Image Source="/SampleBrowser;component/Assets/Icons/stickynote.png" />
                        </toolkit:MenuItem.Icon>
                        <toolkit:MenuItem.Command>
                            <dte:StickyNoteCommand Selection="{StaticResource Selection}" />
                        </toolkit:MenuItem.Command>
                    </toolkit:MenuItem>
                    <toolkit:Separator />
                    <toolkit:MenuItem Header="Hyperlink to firstfloorsoftware.com" CommandParameter="http://firstfloorsoftware.com">
                        <toolkit:MenuItem.Icon>
                            <Image Source="/SampleBrowser;component/Assets/Icons/hyperlink.png" />
                        </toolkit:MenuItem.Icon>
                        <toolkit:MenuItem.Command>
                            <dte:HyperlinkCommand Selection="{StaticResource Selection}" />
                        </toolkit:MenuItem.Command>
                    </toolkit:MenuItem>
                    <toolkit:MenuItem Header="Highlight">
                        <toolkit:MenuItem.Icon>
                            <Image Source="/SampleBrowser;component/Assets/Icons/highlight.png" />
                        </toolkit:MenuItem.Icon>
                        <toolkit:MenuItem.Command>
                            <doc:HighlightCommand Selection="{StaticResource Selection}" />
                        </toolkit:MenuItem.Command>
                    </toolkit:MenuItem>
                    <toolkit:MenuItem Header="Strikethrough">
                        <toolkit:MenuItem.Icon>
                            <Image Source="/SampleBrowser;component/Assets/Icons/strikethrough.png" />
                        </toolkit:MenuItem.Icon>
                        <toolkit:MenuItem.Command>
                            <dte:StrikethroughCommand Selection="{StaticResource Selection}" />
                        </toolkit:MenuItem.Command>
                    </toolkit:MenuItem>
                    <toolkit:MenuItem Header="Underline" CommandParameter="Red">
                        <toolkit:MenuItem.Icon>
                            <Image Source="/SampleBrowser;component/Assets/Icons/underline.png" />
                        </toolkit:MenuItem.Icon>
                        <toolkit:MenuItem.Command>
                            <dte:UnderlineCommand Selection="{StaticResource Selection}" />
                        </toolkit:MenuItem.Command>
                    </toolkit:MenuItem>
                    <toolkit:Separator />
                    <toolkit:MenuItem Header="Remove text annotations">
                        <toolkit:MenuItem.Command>
                            <dte:ClearTextAnnotationsCommand Selection="{StaticResource Selection}" />
                        </toolkit:MenuItem.Command>
                    </toolkit:MenuItem>
                </toolkit:ContextMenu>
            </toolkit:ContextMenuService.ContextMenu>
        </doc:DocumentViewer>

        <StackPanel Grid.ColumnSpan="2" Grid.Row="3" Orientation="Horizontal" Margin="0,8,0,0" HorizontalAlignment="Center">
            <doc:HistoryNavigator History="{Binding History, ElementName=Viewer}" />
            <doc:PageNavigator x:Name="Navigator"
                               PageCount="{Binding PageCount, ElementName=Viewer}"
                               PageIndex="{Binding PageIndex, ElementName=Viewer, Mode=TwoWay}"
                               Margin="4,0,0,0" />
            <doc:ViewModePicker x:Name="ViewModePicker" Margin="4,0,0,0" />
            <Button Command="{Binding PrintCommand, ElementName=Printer}" Margin="4,0,0,0" Padding="7">
                <Button.Content>
                    <Image Source="/SampleBrowser;component/Assets/Icons/print.png" />
                </Button.Content>
            </Button>
        </StackPanel>
    </Grid>
</sdk:Page>
